<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta content="HTML Tidy for Cygwin (vers 1st February 2003), see www.w3.org" name="generator">
    <meta name="keywords" content="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, DevEdge Archive, iPlanet, internet software">
    <meta name="description" content="The DevEdge Archive, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
    <meta name="TEMPLATEBASE" content="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">
    <meta name="LASTUPDATED" content="09/28/00 13:15:35">
    <title>
      Core JavaScript Reference 1.5:
    </title>
    <link rel="stylesheet" type="text/css" href="js15ref.css">
  </head>
  <body>
    <table width="100%" border="0" cellspacing="4">
      <tr>
        <td valign="top">
          <b><a class="sansserifPurple" href="javclass.html">Previous</a></b>&nbsp;&nbsp;&nbsp;&nbsp; <a href="contents.html"><b class="sansserifPurple">Contents</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="ix.html"><b class="sansserifPurple">Index</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="javpkg.html"><b class="sansserifPurple">Next</b></a> &nbsp;&nbsp;&nbsp;&nbsp;
        </td>
      </tr>
      <tr>
        <td class="sansserifBlack" valign="top" align="right" bgcolor="#CCCCCC">
          <b>Core JavaScript Reference 1.5</b>
        </td>
      </tr>
    </table><br>
     
    <blockquote>
      <br>
      <br>
      <br>
      <br>
       
      <p>
        <a name="1193137" id="1193137"></a> <a name="JavaObject" id="JavaObject"></a> <span class="sansserif"><b>JavaObject</b></span>
      </p>
      <p>
        <a name="1193151" id="1193151"></a> <span class="sansserif">The type of a wrapped Java object accessed from within JavaScript code.<br></span>
      </p><br>
       
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1193140" id="1193140"></a> <span class="sansserif"><i>Core object</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193142" id="1193142"></a> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193144" id="1193144"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193146" id="1193146"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193152" id="1193152"></a> <a name="Created by" id="Created by"></a> <span class="sansserif"><b>Created by</b></span><br>
         <a name="1193153" id="1193153"></a> <span class="sansserif">Any Java method which returns an object type. In addition, you can explicitly construct a <span class="mono">JavaObject</span> using the object's Java constructor with the <span class="mono">Packages</span> keyword:</span>
      </p>
      <p>
        <a name="1196676" id="1196676"></a><span class="mono">new Packages.<i>JavaClass</i>(<i>parameterList</i>)</span>
      </p>
      <p>
        <a name="1196829" id="1196829"></a> <span class="sansserif">where <i>JavaClass</i> is the fully-specified name of the object's Java class.</span>
      </p>
      <p>
        <br>
         <a name="1196800" id="1196800"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1196814" id="1196814"></a> <span class="sansserif"><br></span>
      </p><br>
       
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <a name="1196803" id="1196803"></a> <span class="mono">parameterList</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196805" id="1196805"></a> <span class="sansserif">An optional list of parameters, specified by the constructor in the Java class.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193162" id="1193162"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1198206" id="1198206"></a> <span class="sansserif">The <span class="mono">JavaObject</span> object is an instance of a Java class that is created in or passed to JavaScript. <span class="mono">JavaObject</span> is a wrapper for the instance; all references to the class instance are made through the <span class="mono">JavaObject</span>.</span>
      </p>
      <p>
        <a name="1198350" id="1198350"></a> <span class="sansserif">Any Java data brought into JavaScript is converted to JavaScript data types. When the <span class="mono">JavaObject</span> is passed back to Java, it is unwrapped and can be used by Java code. See the <a href="/devedge-srce/library/manuals/2000/javascript/1.5/guide/"><i>Core JavaScript Guide</i></a> for more information about data type conversions.</span>
      </p>
      <p>
        <br>
         <a name="1197132" id="1197132"></a> <a name="Property Summary" id="Property Summary"></a> <span class="sansserif"><b>Property Summary</b></span><br>
         <a name="1197133" id="1197133"></a> <span class="sansserif">Inherits public data members from the Java class of which it is an instance as properties. It also inherits public data members from any superclass as properties.</span>
      </p>
      <p>
        <br>
         <a name="1197134" id="1197134"></a> <a name="Method Summary" id="Method Summary"></a> <span class="sansserif"><b>Method Summary</b></span><br>
         <a name="1196956" id="1196956"></a> <span class="sansserif">Inherits public methods from the Java class of which it is an instance. The <span class="mono">JavaObject</span> also inherits methods from <span class="mono">java.lang.Object</span> and any other superclass.</span>
      </p>
      <p>
        <br>
         <a name="1193209" id="1193209"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
         <a name="1194739" id="1194739"></a> <span class="sansserif"><b>Example 1.</b> Instantiating a Java object in JavaScript.</span>
      </p>
      <p>
        <a name="1197104" id="1197104"></a> <span class="sansserif">The following code creates the <span class="mono">JavaObject</span> <span class="mono">theString</span>, which is an instance of the class <span class="mono">java.lang.String</span>:</span>
      </p>
      <p>
        <a name="1198136" id="1198136"></a><span class="mono">var theString = new Packages.java.lang.String("Hello, world")</span>
      </p>
      <p>
        <a name="1197777" id="1197777"></a> <span class="sansserif">Because the <span class="mono">String</span> class is in the <span class="mono">java</span> package, you can also use the <span class="mono">java</span> synonym and omit the <span class="mono">Packages</span> keyword when you instantiate the class:</span>
      </p>
      <p>
        <a name="1198172" id="1198172"></a><span class="mono">var theString = new java.lang.String("Hello, world")</span>
      </p>
      <p>
        <a name="1198220" id="1198220"></a> <span class="sansserif"><b>Example 2.</b> Accessing methods of a Java object.</span>
      </p>
      <p>
        <a name="1198240" id="1198240"></a> <span class="sansserif">Because the <span class="mono">JavaObject</span> <span class="mono">theString</span> is an instance of <span class="mono">java.lang.String</span>, it inherits all the public methods of <span class="mono">java.lang.String</span>. The following example uses the <span class="mono">startsWith</span> method to check whether <span class="mono">theString</span> begins with "Hello".</span>
      </p>
      <p>
        <a name="1198234" id="1198234"></a><span class="mono">var theString = new java.lang.String("Hello, world")<br>
         theString.startsWith("Hello") // returns true</span>
      </p>
      <p>
        <a name="1198295" id="1198295"></a> <span class="sansserif"><b>Example 3.</b> Accessing inherited methods.</span>
      </p>
      <p>
        <a name="1198170" id="1198170"></a> <span class="sansserif">Because <span class="mono">getClass</span> is a method of <span class="mono">Object</span>, and <span class="mono">java.lang.String</span> extends <span class="mono">Object</span>, the <span class="mono">String</span> class inherits the <span class="mono">getClass</span> method. Consequently, <span class="mono">getClass</span> is also a method of the <span class="mono">JavaObject</span> which instantiates <span class="mono">String</span> in JavaScript.</span>
      </p>
      <p>
        <a name="1198279" id="1198279"></a><span class="mono">var theString = new java.lang.String("Hello, world")<br>
         theString.getClass() // returns java.lang.String</span>
      </p>
      <p>
        <br>
         <a name="1198406" id="1198406"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1198277" id="1198277"></a> <span class="sansserif"><a href="javarray.html#1193137">JavaArray</a>, <a href="javclass.html#1193137">JavaClass</a>, <a href="javpkg.html#1193137">JavaPackage</a>, <a href="packages.html#1193137">Packages</a></span>
      </p>
    </blockquote>
    <blockquote>
      <br>
       <b><a class="sansserifPurple" href="javclass.html">Previous</a></b>&nbsp;&nbsp;&nbsp;&nbsp; <a href="contents.html"><b class="sansserifPurple">Contents</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="ix.html"><b class="sansserifPurple">Index</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="javpkg.html"><b class="sansserifPurple">Next</b></a> &nbsp;&nbsp;&nbsp;&nbsp; 
      <hr noshade="noshade" size="1">
      <span class="sansserif">Copyright &copy; 2000 <a href="http://www.netscape.com">Netscape Communications Corp.</a> All rights reserved.</span>
    </blockquote>
    <p class="alignright">
      <span class="sansserif">Last Updated <b>September 28, 2000</b></span>
    </p>
  </body>
</html>
